package com.pimwi.model
{
  import com.pimwi.dp.ContactDP;
  import com.pimwi.dp.GroupDP;
  import com.pimwi.dp.TaskBarDP;
  import com.pimwi.dp.UserDP;
  import com.pimwi.service.ContactService;
  import com.pimwi.service.GroupService;
  import com.pimwi.service.UserService;
  
  import mx.collections.ArrayCollection;

  [Bindable]
  public class ModelLocator
  {
    public var userDP:UserDP;
    public var userConnected:Boolean;
    public var userContacts:ArrayCollection; // list of ContactDP
    public var userGroups:ArrayCollection; // list of GroupDP

    public var currentContactDP:ContactDP;
    public var currentGroupDP:GroupDP;

    public var userService:UserService;
    public var contactService:ContactService;
    public var groupService:GroupService;

    public var filterGroups:ArrayCollection; // list of GroupDP
    public var filteredContacts:ArrayCollection; // list of ContactDP

    public var taskBarDP:TaskBarDP;

    public function ModelLocator()
    {
      if (_instance != null)
      {
        throw new Error("ModelLocator must be called by ModelLocator.getInstance()");
      }
    }

    private static var _instance:ModelLocator;

    public static function getInstance():ModelLocator
    {
      if (_instance == null)
      {
        _instance = new ModelLocator();
        _instance.initialize();
      }
      return _instance;
    }

    public function initialize():void
    {
      userDP = new UserDP();
      userConnected = false;
      userContacts = new ArrayCollection();
      userGroups = new ArrayCollection();

      currentContactDP = new ContactDP();
      currentGroupDP = new GroupDP();

      userService = new UserService();
      contactService = new ContactService();
      groupService = new GroupService();

      filterGroups = new ArrayCollection();
      filteredContacts = new ArrayCollection();

      taskBarDP = new TaskBarDP();
    }

    public function reset():void
    {
      userConnected = false;
      userContacts.removeAll();
      userGroups.removeAll();
      filterGroups.removeAll();
      filteredContacts.removeAll();
      taskBarDP = new TaskBarDP();
    }

  }
}